

<template>
<van-dialog v-model:show="show"  width="90%" :append-to-body="true" style="max-width: 500px;"
            confirm-button-text="新增单词"
            showConfirmButton show-cancel-button
  @confirm="()=>{
         addMyWords();
      resFun();
  }"
  @cancel="()=>{
    show=false;
  }"

>
  <van-cell-group inset>
    <div class="f-center f-row">
      <el-text style="font-size:32px;">{{input.wordContent}}</el-text>
    </div>

    <van-field label="单词:" size="large" v-model="input.wordContent"  >
      <template #button>
        <van-button @click="()=>{
          getNotMemoryWords();
        }">
              一键生成
        </van-button>
      </template>
    </van-field>
    <van-field label="描述：" v-model="input.description"
               type="textarea"
               maxlength="300"
               rows="3"
               show-word-limit
    ></van-field>

  </van-cell-group>
</van-dialog>
</template>
<script setup>
import {ref,defineExpose} from 'vue';
import {addMyWord, getNotMemoryWord} from "@/apis/apis";
import ret from "@/utils/ret";
import word_logic from "@/pages/wordPage/src/word_logic";
import  config from '@/config'
let show=ref(false);
let resFun=()=>{

}
let input=ref({
  wordContent:"",
  description:""
})
defineExpose({
  apply:function (fun){
    show.value=true;
    resFun=fun;
  }
})
function getNotMemoryWords(){
  getNotMemoryWord({}).then(d=>{
    input.value=d.data.data;

  })
}
function addMyWords(){
  addMyWord({
    "word":input.value.wordContent,
    "des": input.value.description,
    "level": 1
  }).then(d=>{
    if (d.data.code!=-1){
      show.value=false;
      word_logic.addWord(input.value.wordContent,input.value.description,1)
    }
    ret.showRetMessage(d);
    input.value.wordContent="";
    input.value.description="";
  })
}
</script>
<style scoped>

</style>